<template>
  <el-dialog
    class="live-dialog-comp"
    append-to-body
    :title="title"
    :close-on-click-modal="false"
    :destroy-on-close="false"
    :visible="visible"
    :width="$setRem(700)"
    :before-close="handleCancel">
    <div class="live-dialog-container">
      <video-play ref="videoPlay" :data="videoConfig"></video-play>
    </div>
  </el-dialog>
</template>

<script>
import VideoPlay from '@/components/public/Video';

export default {
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    liveOptions: {
      type: Object,
      default: () => ({})
    },
    videoConfig: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {};
  },
  computed: {
    title() {
      const { name_device, nums_device } = this.liveOptions;
      const titleStr = `${name_device} (${nums_device})`;
      return titleStr || '摄像头画面';
    }
  },
  watch: {
    visible(val) {
      if (!val) {
        this.$refs.videoPlay && this.$refs.videoPlay.stop();
      }
    }
  },
  components: {
    VideoPlay
  },
  methods: {
    handleCancel() {
      this.$emit('cancel');
    }
  }
};
</script>

<style scoped lang="scss">
  .live-dialog-comp {
    .live-dialog-container {
      width: 100%;
      height: 500px;
    }
  }
</style>
